/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.curriculum.service.impl;

import cn.afterturn.easypoi.cache.manager.POICacheManager;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.biz.modular.course.entity.EduCourse;
import vip.xiaonuo.biz.modular.course.param.EduCourseExportParam;
import vip.xiaonuo.biz.modular.course.service.EduCourseService;
import vip.xiaonuo.biz.modular.curriculum.param.*;
import vip.xiaonuo.common.enums.CommonSortOrderEnum;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.page.CommonPageRequest;
import vip.xiaonuo.biz.modular.curriculum.entity.EduCurriculum;
import vip.xiaonuo.biz.modular.curriculum.mapper.EduCurriculumMapper;
import vip.xiaonuo.biz.modular.curriculum.service.EduCurriculumService;
import vip.xiaonuo.common.util.CommonDownloadUtil;
import vip.xiaonuo.common.util.CommonResponseUtil;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * 教学计划表Service接口实现类
 *
 * @author ahui
 * @date  2023/05/28 22:59
 **/
@Service
public class EduCurriculumServiceImpl extends ServiceImpl<EduCurriculumMapper, EduCurriculum> implements EduCurriculumService {

    @Resource
    private EduCourseService eduCourseService;

    @Override
    public Page<EduCurriculum> page(EduCurriculumPageParam eduCurriculumPageParam) {
        QueryWrapper<EduCurriculum> queryWrapper = new QueryWrapper<>();
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getCourseCode())) {
            queryWrapper.lambda().like(EduCurriculum::getCourseCode, eduCurriculumPageParam.getCourseCode());
        }
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getCourseName())) {
            queryWrapper.lambda().like(EduCurriculum::getCourseName, eduCurriculumPageParam.getCourseName());
        }
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getCredits())) {
            queryWrapper.lambda().eq(EduCurriculum::getCredits, eduCurriculumPageParam.getCredits());
        }
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getTotalCreditHours())) {
            queryWrapper.lambda().eq(EduCurriculum::getTotalCreditHours, eduCurriculumPageParam.getTotalCreditHours());
        }
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getSemester())) {
            queryWrapper.lambda().eq(EduCurriculum::getSemester, eduCurriculumPageParam.getSemester());
        }
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getCourseType())) {
            queryWrapper.lambda().eq(EduCurriculum::getCourseType, eduCurriculumPageParam.getCourseType());
        }
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getCourseNature())) {
            queryWrapper.lambda().eq(EduCurriculum::getCourseNature, eduCurriculumPageParam.getCourseNature());
        }
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getMajor())) {
            queryWrapper.lambda().eq(EduCurriculum::getMajor, eduCurriculumPageParam.getMajor());
        }
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getType())) {
            queryWrapper.lambda().eq(EduCurriculum::getType, eduCurriculumPageParam.getType());
        }
        if(ObjectUtil.isNotEmpty(eduCurriculumPageParam.getYear())) {
            queryWrapper.lambda().eq(EduCurriculum::getYear, eduCurriculumPageParam.getYear());
        }
        if(ObjectUtil.isAllNotEmpty(eduCurriculumPageParam.getSortField(), eduCurriculumPageParam.getSortOrder())) {
            CommonSortOrderEnum.validate(eduCurriculumPageParam.getSortOrder());
            queryWrapper.orderBy(true, eduCurriculumPageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
                    StrUtil.toUnderlineCase(eduCurriculumPageParam.getSortField()));
        } else {
            queryWrapper.lambda().orderByAsc(EduCurriculum::getId);
        }
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add(EduCurriculumAddParam eduCurriculumAddParam) {
        EduCurriculum eduCurriculum = BeanUtil.toBean(eduCurriculumAddParam, EduCurriculum.class);
        this.save(eduCurriculum);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void edit(EduCurriculumEditParam eduCurriculumEditParam) {
        EduCurriculum eduCurriculum = this.queryEntity(eduCurriculumEditParam.getId());
        BeanUtil.copyProperties(eduCurriculumEditParam, eduCurriculum);
        this.updateById(eduCurriculum);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(List<EduCurriculumIdParam> eduCurriculumIdParamList) {
        // 执行删除
        this.removeByIds(CollStreamUtil.toList(eduCurriculumIdParamList, EduCurriculumIdParam::getId));
    }

    @Override
    public EduCurriculum detail(EduCurriculumIdParam eduCurriculumIdParam) {
        return this.queryEntity(eduCurriculumIdParam.getId());
    }

    @Override
    public EduCurriculum queryEntity(String id) {
        EduCurriculum eduCurriculum = this.getById(id);
        if(ObjectUtil.isEmpty(eduCurriculum)) {
            throw new CommonException("教学计划表不存在，id值为：{}", id);
        }
        return eduCurriculum;
    }

    @Override
    public void downloadImportCurriculumTemplate(HttpServletResponse response) throws IOException {
        try {
            InputStream inputStream = POICacheManager.getFile("curriculumImportTemplate.xlsx");
            byte[] bytes = IoUtil.readBytes(inputStream);
            CommonDownloadUtil.download("教学计划导入模板.xlsx", bytes, response);
        } catch (Exception e) {
            log.error(">>> 下载教学计划导入模板失败：", e);
            CommonResponseUtil.renderError(response, "下载教学计划导入模板失败");
        }
    }

    /**
     * 教学计划导入功能
     *
     * @param file
     * @param major
     * @param type
     * @param year
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public JSONObject importCurriculum(MultipartFile file, String major, String type, Integer year) {
        try {
            int successCount = 0;
            int errorCount = 0;
            JSONArray errorDetail = JSONUtil.createArray();
            // 创建临时文件
            File tempFile = FileUtil.writeBytes(file.getBytes(), FileUtil.file(FileUtil.getTmpDir() +
                    FileUtil.FILE_SEPARATOR + "curriculumImportTemplate.xlsx"));
            // 读取excel
            List<EduCurriculumImportParam> eduCurriculumImportParams = EasyExcel.read(tempFile).head(type.equals("F")? EduCurriculumImportParamF.class: EduCurriculumImportParamB.class).sheet()
                    .headRowNumber(type.equals("F")? 4: 6).doReadSync();
            for (int i = 0; i < eduCurriculumImportParams.size(); i++) {
                JSONObject jsonObject = this.doImport(eduCurriculumImportParams.get(i), i, major, type, year);
                if (jsonObject.getBool("success")) {
                    successCount += 1;
                } else {
                    errorCount += 1;
                    errorDetail.add(jsonObject);
                }
            }
            return JSONUtil.createObj()
                    .set("totalCount", eduCurriculumImportParams.size())
                    .set("successCount", successCount)
                    .set("errorCount", errorCount)
                    .set("errorDetail", errorDetail);
        } catch (Exception e) {
            log.error(">>> 计划导入失败：", e);
            throw new CommonException("计划导入失败");
        }
    }

    /**
     * 教学计划导入到课程
     * @param eduCurriculumExportParam
     */
    @Override
    public void extract(EduCurriculumExportParam eduCurriculumExportParam) {
        //批量增加
        /**
         * 用ids查询到所有对应的educurriculum
         * 然后再创建一个course的空数组 将每个元素遍历循环添加进去
         */
        QueryWrapper<EduCurriculum> eduCurriculumQueryWrapper = new QueryWrapper<>();
        if(ObjectUtil.isNotEmpty(eduCurriculumExportParam.getCurriculumIds())) {
            eduCurriculumQueryWrapper.lambda().in(EduCurriculum::getId, StrUtil.split(eduCurriculumExportParam.getCurriculumIds(), StrUtil.COMMA));
        }
        List<EduCurriculum> eduCurricula = this.list(eduCurriculumQueryWrapper);
        for (EduCurriculum eduCurriculum: eduCurricula) {
            getOrCreateCourse(eduCurriculum);
        }
    }

    private EduCourse getOrCreateCourse(EduCurriculum eduCurriculum) {
        EduCourse eduCourse = new EduCourse();
        eduCourse.setName(eduCurriculum.getCourseName().split("\\|\\|")[0].trim());
        eduCourse.setCredit(eduCurriculum.getCredits());
        eduCourse.setClassHour(convert(eduCurriculum.getTotalCreditHours()));
        eduCourse.setType(StrUtil.indexOfIgnoreCase(eduCurriculum.getCourseNature(), "选修")>-1?"0":"1");
        EduCourse c = eduCourseService.getByName(eduCourse.getName());
        if (ObjectUtil.isNotNull(c)) {
            return c;
        }
        else {
            eduCourseService.save(eduCourse);
            return eduCourse;
        }
    }

    @Override
    public void assign(EduCurriculumAssignParam eduCurriculumAssignParam) {
        QueryWrapper<EduCurriculum> eduCurriculumQueryWrapper = new QueryWrapper<>();
        if (ObjectUtil.isNotEmpty(eduCurriculumAssignParam.getCurriculumIds())) {
            eduCurriculumQueryWrapper.lambda().in(EduCurriculum::getId, StrUtil.split(eduCurriculumAssignParam.getCurriculumIds(), StrUtil.COMMA));
        }
        List<EduCurriculum> eduCurriculumList = this.list(eduCurriculumQueryWrapper);
        List<EduCourse> eduCourseList = new ArrayList<>();
        for (EduCurriculum eduCurriculum: eduCurriculumList) {
            EduCourse eduCourse = getOrCreateCourse(eduCurriculum);
            eduCourseList.add(eduCourse);
        }
        EduCourseExportParam eduCourseExportParam = new EduCourseExportParam();
        BeanUtil.copyProperties(eduCurriculumAssignParam, eduCourseExportParam);
        for (EduCourse eduCourse: eduCourseList) {
            eduCourseService.assign(eduCourse, eduCourseExportParam);
        }
    }

    private Integer convert(String totalCreditHours) {
        if (ObjectUtil.isEmpty(totalCreditHours)) return null;
        if (StringUtils.isNumeric(totalCreditHours)) {
            return Integer.valueOf(totalCreditHours);
        } else {
            return 32 * Integer.valueOf(totalCreditHours.substring(0,1));
        }
    }

    /**
     * 教学计划导出功能
     * @param eduCurriculumExportParam
     * @param response
     */
    @Override
    public void exportCurriculum(EduCurriculumExportParam eduCurriculumExportParam, HttpServletResponse response) {
        return;
//        File tempFile = null;
//        try {
//            QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
//            if(ObjectUtil.isNotEmpty(sysUserExportParam.getUserIds())) {
//                queryWrapper.lambda().in(SysUser::getId, StrUtil.split(sysUserExportParam.getUserIds(), StrUtil.COMMA));
//            } else {
//                if (ObjectUtil.isNotEmpty(sysUserExportParam.getSearchKey())) {
//                    queryWrapper.lambda().like(SysUser::getAccount, sysUserExportParam.getSearchKey())
//                            .or().like(SysUser::getName, sysUserExportParam.getSearchKey())
//                            .or().like(SysUser::getPhone, sysUserExportParam.getSearchKey());
//                }
//                if (ObjectUtil.isNotEmpty(sysUserExportParam.getUserStatus())) {
//                    queryWrapper.lambda().eq(SysUser::getUserStatus, sysUserExportParam.getUserStatus());
//                }
//            }
//            String fileName = "SNOWY2.0系统B端用户信息清单.xlsx";
//            List<SysUser> sysUserList = this.list(queryWrapper);
//            if(ObjectUtil.isEmpty(sysUserList)) {
//                throw new CommonException("无数据可导出");
//            }
//            transService.transBatch(sysUserList);
//            sysUserList = CollectionUtil.sort(sysUserList, Comparator.comparing(SysUser::getOrgId));
//            List<SysUserExportResult> sysUserExportResultList = sysUserList.stream()
//                    .map(sysUser -> {
//                        SysUserExportResult sysUserExportResult = new SysUserExportResult();
//                        BeanUtil.copyProperties(sysUser, sysUserExportResult);
//                        sysUserExportResult.setGroupName(ObjectUtil.isNotEmpty(sysUserExportResult.getOrgName())?
//                                sysUserExportResult.getOrgName():"无组织");
//                        // 状态枚举转为文字
//                        sysUserExportResult.setUserStatus(sysUserExportResult.getUserStatus()
//                                .equalsIgnoreCase(SysUserStatusEnum.ENABLE.getValue())?"正常":"停用");
//                        // 将base64转为byte数组
//                        if (ObjectUtil.isNotEmpty(sysUser.getAvatar())) {
//                            sysUserExportResult.setAvatar(ImgUtil.toBytes(ImgUtil.toImage(StrUtil
//                                    .split(sysUser.getAvatar(), StrUtil.COMMA).get(1)), ImgUtil.IMAGE_TYPE_PNG));
//                        }
//                        return sysUserExportResult;
//                    }).collect(Collectors.toList());
//            // 创建临时文件
//            tempFile = FileUtil.file(FileUtil.getTmpDir() + FileUtil.FILE_SEPARATOR + fileName);
//
//            // 头的策略
//            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
//            WriteFont headWriteFont = new WriteFont();
//            headWriteFont.setFontHeightInPoints((short) 14);
//            headWriteCellStyle.setWriteFont(headWriteFont);
//            // 水平垂直居中
//            headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
//            headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
//
//            // 内容的策略
//            WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//            // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
//            contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
//            // 内容背景白色
//            contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
//            WriteFont contentWriteFont = new WriteFont();
//
//            // 内容字体大小
//            contentWriteFont.setFontHeightInPoints((short) 12);
//            contentWriteCellStyle.setWriteFont(contentWriteFont);
//
//            //设置边框样式，细实线
//            contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
//            contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
//            contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
//            contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
//
//            // 水平垂直居中
//            contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
//            contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
//
//            // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
//            HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle,
//                    contentWriteCellStyle);
//
//            // 写excel
//            EasyExcel.write(tempFile.getPath(), SysUserExportResult.class)
//                    // 自定义样式
//                    .registerWriteHandler(horizontalCellStyleStrategy)
//                    // 自动列宽
//                    .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
//                    // 机构分组合并单元格
//                    .registerWriteHandler(new CommonExcelCustomMergeStrategy(sysUserExportResultList.stream().map(SysUserExportResult::getGroupName)
//                            .collect(Collectors.toList()), 0))
//                    // 设置第一行字体
//                    .registerWriteHandler(new CellWriteHandler() {
//                        @Override
//                        public void afterCellDispose(CellWriteHandlerContext context) {
//                            WriteCellData<?> cellData = context.getFirstCellData();
//                            WriteCellStyle writeCellStyle = cellData.getOrCreateStyle();
//                            Integer rowIndex = context.getRowIndex();
//                            if(rowIndex == 0) {
//                                WriteFont headWriteFont = new WriteFont();
//                                headWriteFont.setFontName("宋体");
//                                headWriteFont.setBold(true);
//                                headWriteFont.setFontHeightInPoints((short) 16);
//                                writeCellStyle.setWriteFont(headWriteFont);
//                            }
//                        }
//                    })
//                    // 设置表头行高
//                    .registerWriteHandler(new AbstractRowHeightStyleStrategy() {
//                        @Override
//                        protected void setHeadColumnHeight(Row row, int relativeRowIndex) {
//                            if(relativeRowIndex == 0) {
//                                // 表头第一行
//                                row.setHeightInPoints(34);
//                            } else {
//                                // 表头其他行
//                                row.setHeightInPoints(30);
//                            }
//                        }
//                        @Override
//                        protected void setContentColumnHeight(Row row, int relativeRowIndex) {
//                            // 内容行
//                            row.setHeightInPoints(20);
//                        }
//                    })
//                    .sheet("用户信息")
//                    .doWrite(sysUserExportResultList);
//            CommonDownloadUtil.download(tempFile, response);
//        } catch (Exception e) {
//            log.error(">>> 用户导出失败：", e);
//            CommonResponseUtil.renderError(response, "用户导出失败");
//        } finally {
//            FileUtil.del(tempFile);
//        }
    }



    /**
     * 执行导入
     *
     * @author xuyuxiang
     * @date 2023/3/7 13:22
     **/
    public JSONObject doImport(EduCurriculumImportParam eduCurriculumImportParam, int i, String major, String type, Integer year) {
        if (type.equals("F")) {
            return doImportF((EduCurriculumImportParamF)eduCurriculumImportParam, i, major, type, year);
        } else {
            return doImportB((EduCurriculumImportParamB)eduCurriculumImportParam, i, major, type, year);
        }
    }

    public JSONObject doImportF(EduCurriculumImportParamF eduCurriculumImportParam, int i, String major, String type, Integer year) {
        String courseType = eduCurriculumImportParam.getCourseType();
        String courseNature = eduCurriculumImportParam.getCourseNature();
        String courseCode = eduCurriculumImportParam.getCourseCode();
        String courseName = eduCurriculumImportParam.getCourseName();
        String credits = eduCurriculumImportParam.getCredits();
        String totalCreditHours = eduCurriculumImportParam.getTotalCreditHours();
        int semester = 0;
        if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester1())) {
            semester = 1;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester2())) {
            semester = 2;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester3())) {
            semester = 3;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester4())) {
            semester = 4;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester5())) {
            semester = 5;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester6())) {
            semester = 6;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester7())) {
            semester = 7;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester8())) {
            semester = 8;
        }
        // 校验必填参数
        if(ObjectUtil.hasEmpty(courseCode, courseName)) {
            return JSONUtil.createObj().set("index", i + 1).set("success", false).set("msg", "必填字段存在空值");
        } else {
            try {

                // 拷贝属性
                EduCurriculum eduCurriculum = new EduCurriculum();
                BeanUtil.copyProperties(eduCurriculumImportParam, eduCurriculum);

                eduCurriculum.setCourseCode(courseCode);
                eduCurriculum.setCredits(credits);
                eduCurriculum.setSemester(semester);

                eduCurriculum.setCourseNature(courseNature);
                eduCurriculum.setTotalCreditHours(totalCreditHours);
                eduCurriculum.setCourseType(courseType);

                eduCurriculum.setMajor(major);
                eduCurriculum.setType(type);
                eduCurriculum.setYear(year);
                // 设置id
                eduCurriculum.setId(IdWorker.getIdStr());
                // 保存或更新
                this.saveOrUpdate(eduCurriculum);

                // 返回成功
                return JSONUtil.createObj().set("success", true);
            } catch (Exception e) {
                log.error(">>> 数据导入异常：", e);
                return JSONUtil.createObj().set("success", false).set("index", i + 1).set("msg", "数据导入异常");
            }
        }
    }
    public JSONObject doImportB(EduCurriculumImportParamB eduCurriculumImportParam, int i, String major, String type, Integer year) {
        String courseType = eduCurriculumImportParam.getCourseType();
        String courseNature = eduCurriculumImportParam.getCourseNature();
        String courseCode = eduCurriculumImportParam.getCourseCode();
        String courseName = eduCurriculumImportParam.getCourseName();
        String credits = eduCurriculumImportParam.getCredits();
        String totalCreditHours = eduCurriculumImportParam.getTotalCreditHours();
        int semester = 0;
        if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester1())) {
            semester = 1;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester2())) {
            semester = 2;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester3())) {
            semester = 3;
        } else if (ObjectUtil.isNotEmpty(eduCurriculumImportParam.getSemester4())) {
            semester = 4;
        }
        // 校验必填参数
        if(ObjectUtil.hasEmpty(courseCode, courseName)) {
            return JSONUtil.createObj().set("index", i + 1).set("success", false).set("msg", "必填字段存在空值");
        } else {
            try {

                // 拷贝属性
                EduCurriculum eduCurriculum = new EduCurriculum();
                BeanUtil.copyProperties(eduCurriculumImportParam, eduCurriculum);

                eduCurriculum.setCourseCode(courseCode);
                eduCurriculum.setCredits(credits);
                eduCurriculum.setSemester(semester);

                eduCurriculum.setCourseNature(courseNature);
                eduCurriculum.setTotalCreditHours(totalCreditHours);
                eduCurriculum.setCourseType(courseType);

                eduCurriculum.setMajor(major);
                eduCurriculum.setType(type);
                eduCurriculum.setYear(year);
                // 设置id
                eduCurriculum.setId(IdWorker.getIdStr());
                // 保存或更新
                this.saveOrUpdate(eduCurriculum);

                // 返回成功
                return JSONUtil.createObj().set("success", true);
            } catch (Exception e) {
                log.error(">>> 数据导入异常：", e);
                return JSONUtil.createObj().set("success", false).set("index", i + 1).set("msg", "数据导入异常");
            }
        }
    }
}
